package graph_interface;

import java.sql.*;

public class DBConnection {
	
	public static Connection getConnection()
	{
		String db="jdbc:mysql://localhost:3306/sport_meeting?"
			+"useSSL=false&allowPublicKeyRetrieval=true&serverTimezone=UTC"
			+"&useUnicode=true&characterEncoding=UTF8";
		Connection conn=null;
		try
		{
			Class.forName("com.mysql.cj.jdbc.Driver");
			System.out.println("注册驱动成功");
		}
		catch(ClassNotFoundException e)
		{
			e.printStackTrace();
		}
		try
		{
			conn=DriverManager.getConnection(db,"root","123456");
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
		return conn;
	}
	public static void main(String[] args) {
		Connection conn=getConnection();
		try
		{
			Statement stmt=conn.createStatement();
			ResultSet rs=stmt.executeQuery("select * from athletes");
			while(rs.next())
			{
				int id=rs.getInt(1);
				String name=rs.getString(2);
				String sex=rs.getString(3);
				System.out.println(id+" "+name+" "+sex);
			}
		}
		catch(SQLException e)
		{
			e.printStackTrace();
		}
	}

}
